home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / rockridge / java / nutsandbolts / alphaexample / CountFile.java < prev    next >
Encoding:
Java Source  |  1995-11-13  |  435 b   |  22 lines

  1. import java.io.*;
  2.  
  3. class CountFile {
  4.     public static void main(String args[]) {
  5.         int count = 0;
  6.     InputStream is;
  7.  
  8.         if (args.length == 1)
  9.         is = new FileInputStream(args[0]);
  10.     else
  11.         is = System.in;
  12.     
  13.         while (is.read() != -1)
  14.             count++;
  15.  
  16.     if (args.length == 1)
  17.         System.out.println(args[0] + " has "+ count + " chars.");
  18.     else
  19.         System.out.println("Input has " + count + " chars.");
  20.     }
  21. }
  22.